package com.pzj.export;

import com.pzj.export.config.ExportConfiguration;


/**
 * 导出工具的工厂
 * @author Puzhijun
 *
 */
public class ExportFactory {

	private static final ExportFactory factory = new ExportFactory();
	@SuppressWarnings("unchecked")
	private final ThreadLocal<ExportExcel> threadLocal = new ThreadLocal<ExportExcel>();
	
	protected ExportFactory(){
	}
	
	/**
	 * 单例方法，获取factory实例
	 * */
	public static ExportFactory getInstance() {
		return factory;
	}
	
	/**
	 * 构造exportExcel对象
	 * */
	public <T> Export<T> getCurrentExport(ExportConfiguration config) {
		@SuppressWarnings("unchecked")
		ExportExcel<T> exportExcel = threadLocal.get();
		if(exportExcel == null) {
			exportExcel = new ExportExcel<T>();
			exportExcel.setExportConfiguration(config);
			threadLocal.set(exportExcel);
		}
		return exportExcel;
	}
	
	/**
	 * 销毁ExportExcel对象
	 * */
	void destroyExportExcel() {
		threadLocal.remove();
	}
	
}
